<script setup lang="ts">
  import { ref, defineEmits, watch, onMounted } from 'vue';
  import { useBooleanStore } from '@/store';
  import { queryCarList } from '@/api/les';

  const emit = defineEmits(['updateArray']);
  const booleanStore = useBooleanStore();
  // 表单查询数据
  const locationCarCode = ref<string>('');
  const toolCode = ref<string>('');

  const pageSize = ref<number>(10);
  const pageNumber = ref<number>(1);

  // 表格数据
  async function handleSearch() {
    const newData = await queryCarList({
      carCode: locationCarCode.value,
      toolCode: toolCode.value,
      current: pageNumber.value,
      size: pageSize.value,
    });
    emit('updateArray', newData);
  }
  // 重置
  function reset() {
    locationCarCode.value = '';
    toolCode.value = '';
    handleSearch();
  }
  onMounted(() => {
    handleSearch();
  });
  // 监听分页
  watch([() => booleanStore.pageNum, () => booleanStore.pageSize], () => {
    if (booleanStore.num5 === 52) {
      pageNumber.value = booleanStore.pageNum;
      pageSize.value = booleanStore.pageSize;
      handleSearch();
    }
  });
  watch(
    () => booleanStore.update,
    () => {
      if (booleanStore.num6 === 31) handleSearch();
    }
  );
</script>

<template>
  <a-row :gutter="{ md: 8, lg: 24, xl: 32 }">
    <a-col :span="6">
      <div>
        <a-input
          v-model="locationCarCode"
          placeholder="料车编码"
          size="large"
        />
      </div>
    </a-col>
    <a-col :span="6">
      <div>
        <a-input v-model="toolCode" placeholder="托盘编码" size="large" />
      </div>
    </a-col>
    <a-col :span="12">
      <a-button type="primary" size="large" @click="handleSearch"
        >查询</a-button
      >
      <a-button class="btn-reset" size="large" @click="reset">重置</a-button>
    </a-col>
  </a-row>
</template>

<style scoped>
  .btn-reset {
    margin-left: 10px;
  }
</style>
